/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package lookandsay;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 *
 * @author Mr.D
 */
public class LookAndSay {

    /**
     * @param args the command line arguments
     */
     public static void GenLookAndSay(int n){
         String currentstring = "", newstring = "", finalstring = "";
         int j = 0, numcount = 1;
         for(int i = 0; i < n; i ++){
             j = 0;
             currentstring = newstring;
             newstring = "";
             if( currentstring.length() == 0){
                        newstring += Integer.toString(numcount);  
             }
             else{
                 while(j <= currentstring.length() - 1){                      
                     if(j == currentstring.length() - 1)
                     {
                        newstring += Integer.toString(numcount) + currentstring.charAt(j);
                        j++;
                        numcount = 1;
                     }
                     else if(currentstring.charAt(j) == currentstring.charAt(j + 1))
                     {
                        j++;
                        numcount++;
                     }
                     else{
                        newstring += Integer.toString(numcount) + currentstring.charAt(j);
                        j++;
                        numcount = 1;
                     }
                 }
             }
             finalstring += newstring + ", ";
         }
         System.out.println(finalstring);
     }
    public static void main(String[] args) {
        // TODO code application logic here
        int num = 0;
        BufferedReader b = new BufferedReader(new InputStreamReader(System.in));
        System.out.print("Nhap so lan: ");
        try{
            num = Integer.parseInt(b.readLine());
        }
        catch(Exception e){}
        GenLookAndSay(num);
    }

}
